local guanwei = fk.CreateSkill {

  name = "joy__guanwei",

  tags = {  },

}



guanwei:addEffect(fk.EventPhaseEnd, {
  name = "joy__guanwei",
  anim_type = "support",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(guanwei.name) and target.phase == Player.Play and
      player:usedSkillTimes(guanwei.name, Player.HistoryTurn) == 0 and not player:isNude() then
        local suits = {}
        local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function (e)
          local use = e.data[1]
          if use.from == target.id then
            if table.contains(suits, use.card.suit) then
              return true
            else
              table.insert(suits, use.card.suit)
            end
          end
          return false
        end, Player.HistoryTurn)
        return #events > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 1, 1, true, guanwei.name, true, ".", "#joy__guanwei-invoke::"..target.id, true)
    if #cards > 0 then
      player.room:doIndicate(player.id, {target.id})
      event:setCostData(self, cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:throwCard(event:getCostData(self), guanwei.name, player, player)
    if not target.dead then
      target:drawCards(2, guanwei.name)
      target:gainAnExtraPhase(Player.Play)
    end
  end,
})

return guanwei